home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / OUI / envman.lha / EnvManager / rcs / envwin.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-23  |  10.6 KB  |  372 lines

  1. head    1.1;
  2. access;
  3. symbols;
  4. locks
  5.     dlorre:1.1; strict;
  6. comment    @// @;
  7.  
  8.  
  9. 1.1
  10. date    96.08.23.16.57.28;    author dlorre;    state Exp;
  11. branches;
  12. next    ;
  13.  
  14.  
  15. desc
  16. @EnvManager : Gestionnaire d'Environnement
  17. Auteur : Dominique Lorre
  18. @
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @#include <exec/types.h>
  27. #include <dos/dosextens.h>
  28. #include <dos/var.h>
  29. #include <libraries/gadtools.h>
  30. #include <cxxproto/dos.h>
  31. #include <cclib/debug_protos.h>
  32. #include <stdio.h>
  33. #include <string.h>
  34.  
  35. #include <screen.h>
  36. #include <gadgets/fbutton.h>
  37. #include <gadgets/cstring.h>
  38. #include <gadgets/cnumber.h>
  39. #include <gadgets/listview.h>
  40. #include <locale.h>
  41.  
  42. #include "envdef.h"
  43. #include "envwin.h"
  44. #include "enventry.h"
  45. #include "envopt.h"
  46.  
  47. IMPORT catalog *ecat ;
  48.  
  49. // Project Menu
  50. lstring __far local(ecat, "L_ocal", 0) ;
  51. lstring __far global(ecat, "G_lobal") ;
  52. lstring __far archive(ecat, "A_rchive") ;
  53. lstring __far locsize(ecat, "Local Size") ;
  54. lstring __far globsize(ecat, "Global Size") ;
  55. lstring __far newentry(ecat, "Create/Search") ;
  56. lstring __far process(ecat, "Process") ;
  57.  
  58. lstring __far newvar(ecat, "Var Name:", 50) ;
  59. lstring __far unnamed(ecat, "UnNamed") ;
  60. lstring __far nothing(ecat, "Nothing") ;
  61.  
  62. lstring __far alias(ecat, "Alias", 100) ;
  63. lstring __far local2(ecat, "Local") ;
  64. lstring __far global2(ecat, "Global") ;
  65. lstring __far archived(ecat, "Archived") ;
  66. lstring __far binary(ecat, "Binary") ;
  67. lstring __far nullterm(ecat, "Null Term") ;
  68. lstring __far vsize(ecat, "Size") ;
  69. lstring __far contents(ecat, "_Contents") ;
  70. lstring __far contents2(ecat, "Contents") ;
  71. lstring __far name(ecat, "_Name") ;
  72. lstring __far edit(ecat, "_Edit") ;
  73. lstring __far import(ecat, "_Import") ;
  74. lstring __far export(ecat, "_Export") ;
  75. lstring __far edition(ecat, "Edition") ;
  76.  
  77. lstring __far importfrom(ecat, "Import from:", 200) ;
  78. lstring __far exportto(ecat, "Export to:") ;
  79.  
  80. STRPTR StringRequest(STRPTR title, STRPTR def) ;
  81.  
  82. IMPORT nlist    *envloclist ;
  83. IMPORT nlist    *envlist ;
  84. IMPORT nlist    *envarclist ;
  85. IMPORT TTextAttr    Tiny ;
  86. IMPORT TTextAttr    Normal ;
  87. IMPORT LONG         envsize ;
  88. IMPORT LONG         envlocsize ;
  89. IMPORT Process      *proc ;
  90.  
  91. enventry *curenv ;
  92.  
  93. void envwindow::updateenv(enventry *curenv,
  94.         BOOL wasarch, BOOL wasglob,
  95.         BOOL isarch, BOOL isglob,
  96.         BOOL fromString)
  97. {
  98. char    path[256] ;
  99. LONG flags ;
  100. enventry *genv ;
  101. enventry *aenv ;
  102.  
  103.     if (wasglob) envsize -= oldsize ;
  104.  
  105.     if (isarch) {
  106.         flags = GVF_GLOBAL_ONLY|GVF_SAVE_VAR ;
  107.         if (curenv->isbinary() && !fromString)
  108.             flags |= GVF_BINARY_VAR ;
  109.         if (!curenv->isnullterm())
  110.             flags |= GVF_DONT_NULL_TERM ;
  111.         if (!wasarch) {
  112.             envarclist->enqueue(new enventry(curenv->name,
  113.                 curenv->contents,
  114.                 curenv->size,
  115.                 ARCHIVED_TYPE)) ;
  116.         }
  117.         SetVar(curenv->name, curenv->contents, curenv->size, flags) ;
  118.     }
  119.     if (isglob) {
  120.         envsize += curenv->size ;
  121.         flags = GVF_GLOBAL_ONLY ;
  122.         if (curenv->isbinary() && !fromString)
  123.             flags |= GVF_BINARY_VAR ;
  124.         if (!curenv->isnullterm())
  125.             flags |= GVF_DONT_NULL_TERM ;
  126.         if (!wasglob) {
  127.             envlist->enqueue(new enventry(curenv->name,
  128.                 curenv->contents,
  129.                 curenv->size,
  130.                 GLOBAL_TYPE)) ;
  131.         }
  132.         SetVar(curenv->name, curenv->contents, curenv->size, flags) ;
  133.     }
  134.     genv = findname(envlist, curenv->name) ;
  135.     aenv = findname(envarclist, curenv->name) ;
  136.     if (wasarch && !isarch) {
  137.         envarclist->remove(aenv) ;
  138.         strcpy(path, "ENVARC:") ;
  139.         AddPart(path, aenv->name, 256) ;
  140.         DeleteFile(path) ;
  141.         delete aenv ;
  142.     }
  143.     if (wasglob && !isglob) {
  144.         envlist->remove(genv) ;
  145.         strcpy(path, "ENV:") ;
  146.         AddPart(path, genv->name, 256) ;
  147.         DeleteFile(path) ;
  148.         delete genv ;
  149.     }
  150.     lglob->reset(envlist, 0, 0) ;
  151.     larc->reset(envarclist, 0, 0) ;
  152.     es->set(envsize) ;
  153. }
  154.  
  155. void envwindow::floclist(gadget *g, ULONG classe, USHORT code)
  156. {
  157. BOOL wasglob ;
  158. BOOL wasarch ;
  159. optwindow *ow ;
  160.  
  161.     curenv = (enventry *)envloclist->get(code) ;
  162.     if (curenv) {
  163.         wasglob = curenv->isglobal() ;
  164.         wasarch = curenv->isarchived() ;
  165.         ow = new optwindow(10, 10, 400, 120) ;
  166.         if (wasglob) oldsize = curenv->size ;
  167.         ow->open(ws) ;
  168.         ow->eventloop() ;
  169.         if (ow->okflag)
  170.             updateenv(curenv, wasarch, wasglob,
  171.                     ow->carch->cursel, ow->cglob->cursel, FALSE) ;
  172.         ow->close() ;
  173.         delete ow ;
  174.     }
  175. }
  176. void envwindow::fenvlist(gadget *g, ULONG classe, USHORT code)
  177. {
  178. optwindow *ow ;
  179. BOOL wasglob ;
  180. BOOL wasarch ;
  181. enventry    *genv ;
  182. BOOL        fromString = FALSE ;
  183.  
  184.     curenv = (enventry *)envlist->get(code) ;
  185.     if (curenv) {
  186.         wasglob = curenv->isglobal() ;
  187.         wasarch = curenv->isarchived() ;
  188.  
  189.         ow = new optwindow(10, 10, 400, 120) ;
  190.         ow->open(ws) ;
  191.         ow->eventloop() ;
  192.         if (ow->okflag) {
  193.             if (ow->scontents) {
  194.                 fromString = TRUE ;
  195.                 delete curenv->contents ;
  196.                 if (wasglob) oldsize = curenv->size ;
  197.                 curenv->size = strlen(ow->scontents->curstring) ;
  198.                 curenv->contents = new char[curenv->size+1] ;
  199.                 strcpy(curenv->contents, ow->scontents->curstring) ;
  200.                 curenv->setentry() ;
  201.                 if (curenv->isarchived()) {
  202.                     genv = findname(envarclist, curenv->name) ;
  203.                     genv->size = curenv->size ;
  204.                     delete genv->contents ;
  205.                     genv->contents = new char[genv->size+1] ;
  206.                     strcpy(genv->contents, curenv->contents);
  207.                     genv->setentry() ;
  208.                 }
  209.             }
  210.             updateenv(curenv, wasarch, wasglob, ow->carch->cursel, ow->cglob->cursel, fromString) ;
  211.         }
  212.         ow->close() ;
  213.         delete ow ;
  214.     }
  215. }
  216. void envwindow::farclist(gadget *g, ULONG classe, USHORT code)
  217. {
  218. optwindow *ow ;
  219. BOOL wasglob ;
  220. BOOL wasarch ;
  221. enventry    *genv ;
  222. BOOL        fromString = FALSE ;
  223.  
  224.     curenv = (enventry *)envarclist->get(code) ;
  225.     if (curenv) {
  226.         wasglob = curenv->isglobal() ;
  227.         wasarch = curenv->isarchived() ;
  228.  
  229.         ow = new optwindow(10, 10, 400, 120) ;
  230.         ow->open(ws) ;
  231.         ow->eventloop() ;
  232.         if (ow->okflag) {
  233.             if (ow->scontents) {
  234.                 fromString = TRUE ;
  235.                 if (wasglob) oldsize = curenv->size ;
  236.                 curenv->size = strlen(ow->scontents->curstring) ;
  237.                 curenv->contents = new char[curenv->size+1] ;
  238.                 strcpy(curenv->contents, ow->scontents->curstring) ;
  239.                 curenv->setentry() ;
  240.                 if (curenv->isglobal()) {
  241.                     genv = findname(envlist, curenv->name) ;
  242.                     genv->size = curenv->size ;
  243.                     delete genv->contents ;
  244.                     genv->contents = new char[genv->size+1] ;
  245.                     strcpy(genv->contents, curenv->contents);
  246.                     genv->setentry() ;
  247.                 }
  248.             }
  249.             updateenv(curenv, wasarch, wasglob, ow->carch->cursel, ow->cglob->cursel, fromString) ;
  250.         }
  251.         ow->close() ;
  252.         delete ow ;
  253.     }
  254. }
  255.  
  256. void envwindow::fnew(gadget *g, ULONG classe, USHORT code)
  257. {
  258. STRPTR name ;
  259. enventry *ev ;
  260.  
  261.     name = StringRequest(newvar, "") ;
  262.     if (name ) {
  263.         if (!strlen(name))
  264.             ev = NULL ;
  265.         else if (!(ev = findvar(name))) {
  266.              if (ev = new enventry(name, nothing,
  267.                 strlen(nothing), GLOBAL_TYPE))
  268.              envlist->enqueue(ev) ;
  269.         }
  270.         delete name ;
  271.         if (ev)
  272.             if (ev->islocale() || ev->isalias())
  273.                 floclist(NULL, NULL, ev->index()) ;
  274.             else if (ev->isglobal())
  275.                 fenvlist(NULL, NULL, ev->index()) ;
  276.             else
  277.                 farclist(NULL, NULL, ev->index()) ;
  278.     }
  279. }
  280.  
  281. void envwindow::fpurge(gadget *g, ULONG classe, USHORT code)
  282. {
  283. }
  284.  
  285. void envwindow::fhelp(gadget *g, ULONG classe, USHORT code)
  286. {
  287. }
  288.  
  289.  
  290. void envwindow::handlevkey(USHORT code)
  291. {
  292.     g->parsegadgets(code) ;
  293. }
  294.  
  295. void envwindow::open(screen *ns)
  296. {
  297. long mw ;
  298. long nl ;
  299. static  char titre[80] ;
  300.  
  301.     ws = ns ;
  302.     sprintf(titre, "EnvManager Â© 1996, D. Lorre, %s: %s",
  303.         process.string, proc->pr_Task.tc_Node.ln_Name) ;
  304.  
  305.     mw = ws->screen->Width - 40 ;
  306.  
  307.     // calcul du nombre de lignes par liste
  308.  
  309.     nl = (ws->screen->Height -                          // Hauteur maxi
  310.          (ws->screen->WBorTop + ws->screen->WBorBottom +// Bords de la fenĂȘtre
  311.          (Tiny.tta_YSize + 12) * 3 +                    // cstrings
  312.          4 * 3 +                                        // listes
  313.          Normal.tta_YSize + 12 +                        // ligne du bas
  314.          + 8)) /                                        // marge
  315.          (3*Tiny.tta_YSize) ;
  316.  
  317.     kprintf("nl = %ld\n", nl) ;
  318.     nl = 4 ;
  319.  
  320.  
  321.     g->setfont(&Tiny) ;
  322.     g->box(20, ws->winbarheight+8, g->ltext(local)+8, g->fontheight+4) ;
  323.     new cstring(g, NULL, local, NULL, FALSE, PLACETEXT_IN|NG_HIGHLABEL) ;
  324.  
  325.  
  326.     g->box(20, g->maxh+8, mw, g->fontheight*nl+4) ;
  327.     lloc = new listview(g, WFUNC(&envwindow::floclist), NULL, NULL, envloclist, 0, 0) ;
  328.  
  329.  
  330.     g->box(20, g->maxh+8, g->ltext(global)+8, g->fontheight+4) ;
  331.     new cstring(g, NULL, global, NULL, FALSE, PLACETEXT_IN|NG_HIGHLABEL) ;
  332.  
  333.     g->box(20, g->maxh+8, mw, g->fontheight*nl+4) ;
  334.     lglob = new listview(g, WFUNC(&envwindow::fenvlist), NULL, NULL, envlist, 0, 0) ;
  335.  
  336.  
  337.     g->box(20, g->maxh+8, g->ltext(archive)+8, g->fontheight+4) ;
  338.     new cstring(g, NULL, archive, NULL, FALSE, PLACETEXT_IN|NG_HIGHLABEL) ;
  339.  
  340.     g->box(20, g->maxh+8, mw, g->fontheight*nl+4) ;
  341.     larc = new listview(g, WFUNC(&envwindow::farclist), NULL, NULL, envarclist, 0, 0) ;
  342.     g->setfont(&Normal) ;
  343.  
  344.  
  345.     g->box(20+g->ltext(globsize)+8, g->maxh+8, g->ltext("999999")+8, g->fontheight+4) ;
  346.     es = new cnumber(g, NULL, globsize, envsize, TRUE, PLACETEXT_LEFT|NG_HIGHLABEL) ;
  347.  
  348.     g->box(g->left+g->width+g->ltext(locsize)+16, g->top, g->ltext("999999")+8, g->fontheight+4) ;
  349.     new cnumber(g, NULL, locsize, envlocsize, TRUE, PLACETEXT_LEFT|NG_HIGHLABEL) ;
  350.  
  351.     g->box(g->left+g->width+8, g->top, g->ltext(newentry)+8, g->fontheight+4) ;
  352.     new fbutton(g, WFUNC(&envwindow::fnew), newentry, FALSE) ;
  353.  
  354.  
  355.     width = short(g->maxw-ws->screen->WBorLeft+20) ;
  356.     height = short(g->maxh-ws->winbarheight+8) ;
  357.  
  358.  
  359.     _open(NULL, SCROLLERIDCMP|ARROWIDCMP|STRINGIDCMP|BUTTONIDCMP|
  360.                 IDCMP_VANILLAKEY|IDCMP_MOUSEBUTTONS|IDCMP_CLOSEWINDOW,
  361.         WA_Title,           titre,
  362.         WA_Gadgets,         g->glist,
  363.         WA_DragBar,         TRUE,
  364.         WA_DepthGadget,     TRUE,
  365.         WA_CloseGadget,     TRUE,
  366.         WA_Activate,        TRUE,
  367.         TAG_DONE) ;
  368.  
  369.     if (initok) g->updategadgets() ;
  370. }
  371. @
  372.